package edu.kit.los.event;

import java.util.Date;

import edu.kit.los.util.Converter;

/**
 * @author Benedikt
 * @deprecated direkt FacebookEvent nutzen
 */
public class FacebookEventOld {
	private long ID;
	private String name;
	private String description;
	private Date start_time;
	private Date end_time;
	private Date updated_time;
	private String privacy;
	
	private String owner_name;
	private long owner_ID;
	
	private String location;
	private double geo_lat;
	private double geo_long;
	private long geo_ID;	
	
	public FacebookEventOld(){
		this.ID =  (long) (10000000*Math.random());
	}
	
	/**
	 * Minimal-Konstruktor f�r Facebook-EventPrototype. Es erfolgt im Vergleich zum Standard-Konstruktor
	 * keine �berpr�fung der Dateninhalte.
	 * @param ID
	 * @param name
	 * @param description
	 * @param geo_lat
	 * @param geo_long
	 */
	public FacebookEventOld(String ID, String name, String description, String geo_lat, String geo_long){
		this.ID = Long.parseLong(ID);
		this.name = name;
		this.description = description;
		if (geo_lat != null) this.geo_lat = Double.parseDouble(geo_lat);
		if (geo_long != null)this.geo_long = Double.parseDouble(geo_long);
	}
	
	/**
	 * Standard-Konstruktor f�r Facebook-EventPrototype. Felder, welche mit null belegt werden, 
	 * werden mit einem Standardwert �berschrieben.
	 * @param ID
	 * @param name
	 * @param description
	 * @param start_time
	 * @param end_time
	 * @param updated_time
	 * @param privacy
	 * @param owner_name
	 * @param owner_ID
	 * @param location
	 * @param geo_lat
	 * @param geo_long
	 * @param geo_ID
	 */
	public FacebookEventOld (
			String ID,
			String name,
			String description,
			String start_time,
			String end_time,
			String updated_time,
			String privacy,
			String owner_name,
			String owner_ID,
			String location,
			double geo_lat,
			double geo_long,
			String geo_ID){

		//String-Zuweisungen und Fehlerbehandlung
		if (name        == null) name         = "";
		if (description == null) description  = "";
		if (owner_name  == null) owner_name   = "";
		if (location    == null) location     = "";
		if (privacy     == null) privacy      = "OPEN";
		
		this.name        = name;
		this.description = description;
		this.location    = location;
		this.owner_name  = owner_name;
		this.privacy     = privacy;
		
		//Datums-Zuweisungen
		if (start_time   == null) start_time   = "2000-01-01-00:00:00";
		if (end_time     == null) end_time     = "2000-01-01-00:00:00";
		if (updated_time == null) updated_time = "2000-01-01-00:00:00";
		this.start_time   = Converter.FacebookDate2JavaDate(start_time);
		this.end_time     = Converter.FacebookDate2JavaDate(end_time);
		this.updated_time = Converter.FacebookDate2JavaDate(updated_time);
		
		
		//Zahlen
		if (ID          == null) ID       = "0";
		if (owner_ID    == null) owner_ID = "0";		
//		if (geo_lat     == null) geo_lat  = "0";
//		if (geo_long    == null) geo_long = "0";
		if (geo_ID      == null) geo_ID   = "0";
		try {
			this.ID = Long.parseLong(ID);
		}
		catch (NumberFormatException nfe) {
			this.ID = 0;
			System.out.println("Falsche EventPrototype-Nummer:\t"+ID);
		}
		try {
			this.owner_ID = Long.parseLong(owner_ID);
		}
		catch (NumberFormatException nfe) {
			this.owner_ID = 0;
			System.out.println("Falsche Owner-ID:\t"+owner_ID);
		}
//		try {
//			this.geo_lat  = Double.parseDouble(geo_lat);
//		}
//		catch (NumberFormatException nfe) {
//			this.geo_lat = 0;
//			System.out.println("Latitude falsch:\t"+geo_lat);
//		}
//		try {
//			this.geo_long = Double.parseDouble(geo_long);
//		}
//		catch (NumberFormatException nfe) {
//			this.geo_long = 0;
//			System.out.println("Longitude falsch:\t"+geo_long);
//		}
		try {
			this.geo_ID   = Long.parseLong(geo_ID);
		}
		catch (NumberFormatException nfe) {
			this.geo_ID = 0;
			System.out.println("Geo-ID falsch:\t"+geo_ID);
		}
	}
	
	/**
	 * Stellt ein FacebookEvent als Zeile einer Tabelle dar.
	 * @deprecated Nicht mehr verwenden. Aktuelle Version ist in FacebookEvent
	 * @return Tabellenzeile (HTML-Code)
	 */
	public String toHTML(){
		String result = ""
			+ "<tr>\n"
			+ "  <td>" + ID           +"</td>\n"
			+ "  <td>" + name         +"</td>\n"
			+ "  <td>" + description  +"</td>\n"
			+ "  <td>" + start_time   +"</td>\n"
			+ "  <td>" + end_time     +"</td>\n"
			+ "  <td>" + updated_time +"</td>\n"
			+ "  <td>" + privacy      +"</td>\n"
			+ "  <td>" + owner_name   +"</td>\n"
			+ "  <td>" + owner_ID     +"</td>\n"
			+ "  <td>" + location     +"</td>\n"
			+ "  <td>" + geo_lat      +"</td>\n"
			+ "  <td>" + geo_long     +"</td>\n"
			+ "  <td>" + geo_ID       +"</td>\n"
		    + "</tr>\n"; 
	    return result;
	}
	
	/**
	 * Gibt einen String f�r das Objekt in der Form \"FacebookEvent: [ID des Events]\" zur�ck.
	 */
	public String toString(){
		return "FacebookEvent "+ID;
	}
	
	/**
	 * Erzeugt einen Punkt (Placemark) f�r eine KML-Datei mit folgenden Infos: Name, Description, Koordinaten.
	 * @deprecated Nicht mehr verwenden. Aktuelle Version ist in FacebookEvent
	 * @return Darstellung des Punktes im KML-Format
	 */
	public String toKML(){
		String result = ""
				+ "  <Placemark>\n"
				+ "    <name>" + this.name + "</name>\n"
				+ "    <description>" + this.description + "</description>\n"
				+ "    <Point>\n"
				+ "      <coordinates>" + this.geo_lat + "," + this.geo_long + ",0</coordinates>\n"
				+ "    </Point>\n"
				+ "  </Placemark>\n";
		return result;		
	}
}
